import { Module } from 'vuex'
import GlobalDataProps from '../types'

interface Http {
  cancelTokenArr: any[]
}

const http: Module<Http, GlobalDataProps> = {
  namespaced: true,
  state: {
    cancelTokenArr: [] // 取消请求token数组
  },
  getters: {},
  mutations: {
    pushToken(state, payload) {
      state.cancelTokenArr.push(payload.cancelToken)
    },
    clearToken({ cancelTokenArr }) {
      cancelTokenArr.forEach(item => {
        item('路由跳转取消请求')
      })
      cancelTokenArr = []
    }
  },
  actions: {}
}
export default http
